// 类
class Animal {
  name: string
  protected sex: string
  private age: number
  constructor(name: string, sex: string, age: number) {
    this.name = name
    this.sex = sex
    this.age = age
  }
  move(distance: number = 23) {
    return `my name is ${this.name}，i am ${this.age} years old，move ${distance}m`
  }
}
let snake = new Animal('snake', '男', 18)
console.log(snake.name)
console.log(snake.move())
console.log(snake.move(100))
// console.log(snake.sex) //私有private变量不允许在外部访问

// 类的继承
class Dog extends Animal {
  constructor(name: string, sex: string, age: number) {
    super(name, sex, age)
  }
  bark() {
    // console.log('wang wang wang~~~')
    console.log('wang wang wang~~~', this.sex) //父类的受保护的变量可以在子类中使用
    // console.log('wang wang wang~~~', this.age) //报错,父类的私有变量不能在子类中使用
  }
}
let dog = new Dog('dog', '女', 22)
dog.bark()
console.log(dog.name)
console.log(dog.move(99))

// 类的私有private和protected变量不允许在外部访问
// console.log(snake.age)   //报错
// console.log(snake.sex)   //报错
// console.log(dog.sex)     //报错
